package com.zdp.contentcenter.feignclient.fallbackfactory;

import com.zdp.contentcenter.domain.dto.user.UserDTO;
import com.zdp.contentcenter.feignclient.UserCenterFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author sesshomaru
 * @date 2020/9/20 18:34
 *
 * 这个可以打印错误日志也可以降级
 */
@Component
@Slf4j
public class UserCenterFeignClientFallbackFactory implements FallbackFactory {

    @Override
    public Object create(Throwable e) {
        return new UserCenterFeignClient() {
            @Override
            public UserDTO findById(Integer id) {
                log.warn("远程调用被限流/降级了", e);
                UserDTO userDTO = new UserDTO();
                userDTO.setWxNickname("远程调用被限流/降级了返回的默认用户");
                return userDTO;
            }
        };
    }
}
